package Fangfalianxi;

import java.util.Random;
import java.util.Scanner;

//双色球
public class test9 {
    public static void main(String[] args) {
        //1.生成中奖号码
        int[] arr = crateNumber();
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
        System.out.println();

        //2.用户输入号码
        int[] arr1 = userInputNumber();

        //3.判断用户的中奖情况
         int redcount = 0;
         int bluecount = 0;
        for (int i = 0; i < arr1.length-1; i++) {
            int rednumber = arr1[i];
            for (int j = 0; j < arr.length; j++) {
                if(rednumber==arr[j]){
                    redcount++;
                    break;
                }
            }
        }
        int bluenumber = arr1[arr1.length-1];
        if(bluenumber == arr[arr.length-1]){
            bluecount++;
        }
        if(redcount==6 && bluecount==1){
            System.out.println("恭喜你，中奖1000万");
        }else if(redcount==6 && bluecount==0){
            System.out.println("恭喜你，中奖500万");
        }else if(redcount==5 && bluecount==1){
            System.out.println("恭喜你，中奖3000");
        }else if((redcount==5 && bluecount==0) || (redcount==4 && bluecount==1)){
            System.out.println("恭喜你，中奖200");
        }else if((redcount==4 && bluecount==0) || (redcount==3 && bluecount==1)){
            System.out.println("恭喜你，中奖10");
        }else if((redcount==2 && bluecount==1) || (redcount==1 && bluecount==1) || (redcount==0) && bluecount==1){
            System.out.println("恭喜你，中奖5");
        }else{
            System.out.println("谢谢参与，谢谢惠顾");
        }
    }

    public static int[] userInputNumber(){
        int[] arr = new int[7];
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < arr.length-1; ) {
            System.out.println("请输入第"+(i+1)+"个红球号码：");
            int rednumber = sc.nextInt();
            if(rednumber>=1 && rednumber<=33){
                boolean flag = contains(arr,rednumber);
                if(!flag){
                    arr[i] = rednumber;
                    i++;
                }else{
                    System.out.println("当前红球号码已经存在，请重新输入");
                }
            }else{
                System.out.println("当前红球号码超出范围");
            }
        }
        while(true) {
            System.out.println("请输入蓝球的号码：");
            int bluenumber = sc.nextInt();
            if (bluenumber >= 1 && bluenumber <= 16) {
                arr[arr.length - 1] = bluenumber;
                break;
            } else {
                System.out.println("当前蓝球的号码超出范围");
            }
        }
        return arr;
    }

    public static int[] crateNumber(){
        int[] arr = new int[7];
        Random r = new Random();
        for (int i = 0; i < 6; ) {
            int rednumber = r.nextInt(33)+1;
            boolean flag = contains(arr,rednumber);
            if(!flag){
                arr[i] = rednumber;
                i++;
            }
        }
        int bluenumber = r.nextInt(16)+1;
        arr[arr.length-1] = bluenumber;
        return arr;
    }

    public static boolean contains(int[] arr,int number){
        for (int i = 0; i < arr.length; i++) {
            if(arr[i]==number){
                return true;
            }
        }
        return false;
    }
}
